﻿using HeinQi.Framework.LayerBases;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TbShop.Entity
{
    public class SelectItemEntityBase : DataEntityBase
    {
        public virtual string Name { set; get; }
    }

    public class DataEntityBase : EntityBase
    {
        public bool IsDeleted { set; get; }
    }

    public static class DataEntityBaseExtension
    {
        /// <summary>
        /// 扩展方法，设置公共字段
        /// </summary>
        /// <param name="item">实体对象</param>
        /// <param name="operationUser">操作人</param>
        public static void FillEntity(this EntityBase item, string operationUser)
        {
            if (item.Id <= 0)
            {
                item.VersionNumber = 1;
                item.CreatedDate = DateTime.Now;
                item.CreatedBy = operationUser;
            }
            else
            {
                item.VersionNumber++;
            }
            item.UpdatedDate = DateTime.Now;
            item.UpdatedBy = operationUser;
        }
    }
}
